<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>专业支持资源 - AI治疗师</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js"></script>
    <link href="https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;600;700&family=Inter:wght@300;400;500;600&display=swap" rel="stylesheet">
    <style>
        :root {
            --primary-color: #4A90A4;
            --secondary-color: #F5F3F0;
            --accent-color: #2E7D32;
            --warning-color: #FF8A65;
            --text-dark: #2C3E50;
            --text-light: #7F8C8D;
        }
        
        body {
            font-family: 'Inter', sans-serif;
            background: linear-gradient(135deg, var(--secondary-color) 0%, #E8F4F8 100%);
            min-height: 100vh;
        }
        
        .hero-title {
            font-family: 'Playfair Display', serif;
            background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        .support-card {
            background: rgba(255, 255, 255, 0.9);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(74, 144, 164, 0.1);
            transition: all 0.3s ease;
        }
        
        .support-card:hover {
            transform: translateY(-3px);
            box-shadow: 0 15px 35px rgba(0,0,0,0.1);
        }
        
        .resource-item {
            background: rgba(255, 255, 255, 0.8);
            backdrop-filter: blur(5px);
            transition: all 0.3s ease;
        }
        
        .resource-item:hover {
            background: rgba(255, 255, 255, 0.95);
            transform: translateX(5px);
        }
        
        .appointment-card {
            background: rgba(255, 255, 255, 0.9);
            backdrop-filter: blur(10px);
            border-left: 4px solid #4A90A4;
        }
        
        .modal {
            backdrop-filter: blur(10px);
        }
        
        .rating-stars {
            color: #FCD34D;
        }
        
        .available-badge {
            background: linear-gradient(135deg, #10B981, #059669);
        }
        
        .busy-badge {
            background: linear-gradient(135deg, #F59E0B, #D97706);
        }
        
        .offline-badge {
            background: linear-gradient(135deg, #6B7280, #4B5563);
        }
        
        .search-highlight {
            background-color: #FEF3C7;
            padding: 1px 2px;
            border-radius: 2px;
        }
        
        .appointment-slot {
            transition: all 0.2s ease;
        }
        
        .appointment-slot:hover {
            background-color: #EBF8FF;
            transform: scale(1.02);
        }
        
        .appointment-slot.selected {
            background-color: #3B82F6;
            color: white;
        }
        
        .appointment-slot.booked {
            background-color: #F3F4F6;
            color: #9CA3AF;
            cursor: not-allowed;
        }
    </style>
</head>
<body class="text-gray-800">
    
    <!-- Navigation -->
    <nav class="bg-white/80 backdrop-blur-md shadow-sm border-b border-gray-100 sticky top-0 z-50">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex justify-between items-center h-16">
                <div class="flex items-center space-x-3">
                    <div class="w-10 h-10 bg-gradient-to-br from-blue-500 to-teal-500 rounded-full flex items-center justify-center">
                        <span class="text-white font-bold text-lg">🤖</span>
                    </div>
                    <span class="text-xl font-semibold text-gray-800">AI治疗师</span>
                </div>
                <div class="hidden md:flex space-x-8">
                    <a href="index.html" class="text-gray-600 hover:text-blue-600 transition-colors">治疗对话</a>
                    <a href="monitoring.html" class="text-gray-600 hover:text-blue-600 transition-colors">情绪监测</a>
                    <a href="crisis.html" class="text-gray-600 hover:text-blue-600 transition-colors">危机支持</a>
                    <a href="support.html" class="text-blue-600 font-medium border-b-2 border-blue-600 pb-1">专业支持</a>
                    <a href="about.html" class="text-gray-600 hover:text-blue-600 transition-colors">关于系统</a>
                </div>
                <button class="md:hidden p-2 rounded-md text-gray-600 hover:text-blue-600">
                    <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"></path>
                    </svg>
                </button>
            </div>
        </div>
    </nav>

    <!-- Header -->
    <section class="pt-12 pb-8">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="text-center mb-8">
                <h1 class="hero-title text-4xl md:text-5xl font-bold mb-4 opacity-0" id="main-title">
                    专业支持资源
                </h1>
                <p class="text-lg text-gray-600 max-w-2xl mx-auto mb-6 opacity-0" id="subtitle">
                    全面的心理健康专业服务，包括在线咨询、支持小组、资源库和医生定位
                </p>
            </div>
        </div>
    </section>

    <!-- Online Counseling -->
    <section class="pb-12">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="text-center mb-8">
                <h2 class="text-3xl font-bold text-gray-800 mb-4">在线心理咨询</h2>
                <p class="text-lg text-gray-600">专业心理咨询师提供24/7在线服务</p>
            </div>
            
            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 mb-8" id="counselors-container">
                <!-- Counselor cards will be generated here -->
            </div>
            
            <div class="text-center">
                <button onclick="showAllCounselors()" class="bg-gradient-to-r from-blue-500 to-teal-500 text-white px-8 py-3 rounded-full font-medium hover:shadow-lg transform hover:scale-105 transition-all duration-300">
                    查看所有咨询师
                </button>
            </div>
        </div>
    </section>

    <!-- Support Groups -->
    <section class="pb-12">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="text-center mb-8">
                <h2 class="text-3xl font-bold text-gray-800 mb-4">互助支持小组</h2>
                <p class="text-lg text-gray-600">与经历相似困扰的人分享经验，互相支持</p>
            </div>
            
            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 mb-8" id="support-groups-container">
                <!-- Support group cards will be generated here -->
            </div>
            
            <div class="text-center">
                <button onclick="createSupportGroup()" class="bg-gradient-to-r from-green-500 to-emerald-500 text-white px-8 py-3 rounded-full font-medium hover:shadow-lg transform hover:scale-105 transition-all duration-300">
                    创建新的小组
                </button>
            </div>
        </div>
    </section>

    <!-- Resource Library -->
    <section class="pb-12">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="text-center mb-8">
                <h2 class="text-3xl font-bold text-gray-800 mb-4">自助资源库</h2>
                <p class="text-lg text-gray-600">丰富的心理健康资源，包括文章、视频、音频和互动练习</p>
            </div>
            
            <div class="mb-6">
                <div class="flex flex-col md:flex-row gap-4">
                    <div class="flex-1">
                        <input type="text" id="resource-search" placeholder="搜索心理健康资源..." class="w-full px-4 py-3 border border-gray-200 rounded-2xl focus:outline-none focus:ring-2 focus:ring-blue-500">
                    </div>
                    <div class="flex gap-2">
                        <select id="resource-category" class="px-4 py-3 border border-gray-200 rounded-2xl focus:outline-none focus:ring-2 focus:ring-blue-500">
                            <option value="">所有类别</option>
                            <option value="anxiety">焦虑管理</option>
                            <option value="depression">抑郁应对</option>
                            <option value="stress">压力管理</option>
                            <option value="mindfulness">正念冥想</option>
                            <option value="sleep">睡眠改善</option>
                            <option value="relationship">人际关系</option>
                        </select>
                        <button onclick="searchResources()" class="bg-blue-500 text-white px-6 py-3 rounded-2xl hover:bg-blue-600 transition-colors">
                            搜索
                        </button>
                    </div>
                </div>
            </div>
            
            <div id="resource-results" class="space-y-4">
                <!-- Search results will be displayed here -->
            </div>
        </div>
    </section>

    <!-- Professional Directory -->
    <section class="pb-12">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="text-center mb-8">
                <h2 class="text-3xl font-bold text-gray-800 mb-4">专业医生目录</h2>
                <p class="text-lg text-gray-600">查找附近的心理健康专业人士</p>
            </div>
            
            <div class="mb-6">
                <div class="flex flex-col md:flex-row gap-4">
                    <div class="flex-1">
                        <input type="text" id="location-search" placeholder="输入您的位置..." class="w-full px-4 py-3 border border-gray-200 rounded-2xl focus:outline-none focus:ring-2 focus:ring-blue-500">
                    </div>
                    <div class="flex gap-2">
                        <select id="doctor-specialty" class="px-4 py-3 border border-gray-200 rounded-2xl focus:outline-none focus:ring-2 focus:ring-blue-500">
                            <option value="">所有专业</option>
                            <option value="psychiatrist">精神科医生</option>
                            <option value="psychologist">临床心理师</option>
                            <option value="therapist">心理治疗师</option>
                            <option value="counselor">心理咨询师</option>
                        </select>
                        <button onclick="searchDoctors()" class="bg-orange-500 text-white px-6 py-3 rounded-2xl hover:bg-orange-600 transition-colors">
                            查找
                        </button>
                    </div>
                </div>
            </div>
            
            <div id="doctor-results" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
                <!-- Doctor search results will be displayed here -->
            </div>
        </div>
    </section>

    <!-- My Appointments -->
    <section class="pb-12">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="text-center mb-8">
                <h2 class="text-3xl font-bold text-gray-800 mb-4">我的预约</h2>
                <p class="text-lg text-gray-600">管理您的咨询预约和支持小组</p>
            </div>
            
            <div id="appointments-container" class="space-y-4">
                <!-- Appointments will be displayed here -->
            </div>
        </div>
    </section>

    <!-- Footer -->
    <footer class="bg-gray-800 text-white py-8">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 text-center">
            <p class="text-gray-400">© 2024 AI治疗师. 专业的心理健康支持系统. 保护您的隐私是我们的首要责任.</p>
            <p class="text-gray-500 text-sm mt-2">免责声明：本系统不能替代专业医疗建议，如有紧急情况请立即联系医疗专业人员</p>
        </div>
    </footer>

    <script>
        // Global data storage
        let counselorsData = [];
        let supportGroupsData = [];
        let resourcesData = [];
        let doctorsData = [];
        let userAppointments = [];

        // Initialize page
        document.addEventListener('DOMContentLoaded', function() {
            initializeAnimations();
            initializeData();
            loadUserData();
            renderAllComponents();
        });

        // Initialize animations
        function initializeAnimations() {
            anime.timeline({
                easing: 'easeOutExpo',
                duration: 1000
            })
            .add({
                targets: '#main-title',
                opacity: [0, 1],
                translateY: [50, 0],
                delay: 300
            })
            .add({
                targets: '#subtitle',
                opacity: [0, 1],
                translateY: [30, 0],
                delay: 200
            }, '-=800');

            anime({
                targets: '.support-card',
                opacity: [0, 1],
                translateY: [50, 0],
                delay: anime.stagger(200, {start: 600}),
                duration: 800,
                easing: 'easeOutExpo'
            });
        }

        // Initialize data
        function initializeData() {
            // Initialize counselors data
            counselorsData = [
                {
                    id: 1,
                    name: '李心理博士',
                    specialty: '认知行为疗法',
                    experience: '12年经验',
                    rating: 4.9,
                    reviews: 328,
                    status: 'available',
                    image: '👨‍⚕️',
                    price: '¥200/小时',
                    languages: ['中文', '英文'],
                    description: '专业认知行为治疗师，擅长焦虑症、抑郁症治疗',
                    nextAvailable: '今天 15:00-16:00',
                    specialties: ['焦虑', '抑郁', '恐慌症', '强迫症']
                },
                {
                    id: 2,
                    name: '王治疗师',
                    specialty: '创伤治疗',
                    experience: '8年经验',
                    rating: 4.8,
                    reviews: 256,
                    status: 'available',
                    image: '👩‍⚕️',
                    price: '¥180/小时',
                    languages: ['中文'],
                    description: '创伤治疗专家，EMDR治疗师',
                    nextAvailable: '今天 16:30-17:30',
                    specialties: ['创伤后应激', '童年创伤', '情感创伤']
                },
                {
                    id: 3,
                    name: '张心理师',
                    specialty: '焦虑抑郁',
                    experience: '15年经验',
                    rating: 4.9,
                    reviews: 412,
                    status: 'busy',
                    image: '👨‍⚕️',
                    price: '¥250/小时',
                    languages: ['中文', '英文', '日文'],
                    description: '资深心理咨询师，多元化治疗方式',
                    nextAvailable: '明天 10:00-11:00',
                    specialties: ['广泛性焦虑', '社交恐惧', '抑郁症']
                }
            ];

            // Initialize support groups data
            supportGroupsData = [
                {
                    id: 1,
                    name: '焦虑症互助小组',
                    description: '为焦虑症患者提供相互支持和经验分享的平台',
                    members: 1247,
                    active: true,
                    nextMeeting: '今晚 20:00',
                    category: 'anxiety',
                    facilitator: '专业心理师',
                    type: '线上会议',
                    meetingDay: '每周三',
                    duration: '60分钟',
                    maxMembers: 15,
                    currentMembers: 12
                },
                {
                    id: 2,
                    name: '抑郁康复之路',
                    description: '抑郁症患者的康复支持和学习小组',
                    members: 892,
                    active: true,
                    nextMeeting: '明天 19:30',
                    category: 'depression',
                    facilitator: '康复患者',
                    type: '线上会议',
                    meetingDay: '每周四',
                    duration: '90分钟',
                    maxMembers: 20,
                    currentMembers: 16
                },
                {
                    id: 3,
                    name: '压力管理工作坊',
                    description: '学习有效的压力管理技巧和放松方法',
                    members: 634,
                    active: false,
                    nextMeeting: '周六 14:00',
                    category: 'stress',
                    facilitator: '专业治疗师',
                    type: '线下活动',
                    meetingDay: '每周六',
                    duration: '120分钟',
                    maxMembers: 10,
                    currentMembers: 8
                }
            ];

            // Initialize resources data
            resourcesData = [
                {
                    id: 1,
                    title: '认知行为疗法基础指南',
                    category: 'anxiety',
                    type: '文章',
                    duration: '15分钟阅读',
                    description: '了解CBT的基本原理和如何在日常生活中应用这些技巧来管理焦虑和负面情绪。',
                    tags: ['CBT', '焦虑', '思维重构'],
                    author: '李心理博士',
                    date: '2024-09-15',
                    content: '认知行为疗法（CBT）是一种有效的心理治疗方法，它帮助我们识别和改变负面思维模式...',
                    readCount: 2847,
                    rating: 4.8
                },
                {
                    id: 2,
                    title: '正念冥想入门音频',
                    category: 'mindfulness',
                    type: '音频',
                    duration: '20分钟',
                    description: '专业的正念冥想指导音频，帮助您学习专注当下，减少压力和焦虑。',
                    tags: ['正念', '冥想', '放松'],
                    author: '正念教练团队',
                    date: '2024-10-01',
                    content: '这是一个20分钟的正念冥想练习，请找一个安静的地方，闭上眼睛，跟随指导进行练习...',
                    readCount: 1923,
                    rating: 4.9
                },
                {
                    id: 3,
                    title: '睡眠改善实用技巧',
                    category: 'sleep',
                    type: '视频',
                    duration: '12分钟',
                    description: '睡眠专家分享的科学睡眠方法，包括睡眠卫生习惯和改善睡眠质量的具体技巧。',
                    tags: ['睡眠', '失眠', '睡眠卫生'],
                    author: '睡眠研究中心',
                    date: '2024-09-28',
                    content: '良好的睡眠对心理健康至关重要。本视频将介绍科学的睡眠方法和实用的改善技巧...',
                    readCount: 3456,
                    rating: 4.7
                },
                {
                    id: 4,
                    title: '压力管理工作手册',
                    category: 'stress',
                    type: 'PDF',
                    duration: '30页',
                    description: '全面的压力管理指南，包含实用的工作表和练习，帮助您识别和应对生活中的压力源。',
                    tags: ['压力管理', '工作表', '应对策略'],
                    author: '压力管理专家',
                    date: '2024-10-05',
                    content: '这份30页的工作手册包含了全面的压力管理策略和实用的练习工作表...',
                    readCount: 1567,
                    rating: 4.6
                }
            ];

            // Initialize doctors data
            doctorsData = [
                {
                    id: 1,
                    name: '张精神科医生',
                    specialty: '精神科医生',
                    hospital: '北京协和医院',
                    rating: 4.9,
                    reviews: 156,
                    distance: '2.3公里',
                    price: '¥300/次',
                    availability: '可预约',
                    image: '👨‍⚕️',
                    address: '北京市东城区帅府园1号',
                    phone: '010-69156114',
                    specialties: ['抑郁症', '焦虑症', '双相情感障碍'],
                    education: '北京大学医学博士',
                    experience: '20年临床经验'
                },
                {
                    id: 2,
                    name: '李临床心理师',
                    specialty: '临床心理师',
                    hospital: '北京大学第六医院',
                    rating: 4.8,
                    reviews: 203,
                    distance: '3.1公里',
                    price: '¥250/次',
                    availability: '可预约',
                    image: '👩‍⚕️',
                    address: '北京市海淀区花园北路51号',
                    phone: '010-82801936',
                    specialties: ['认知行为治疗', '心理评估', '团体治疗'],
                    education: '中科院心理所博士',
                    experience: '15年临床经验'
                },
                {
                    id: 3,
                    name: '王心理治疗师',
                    specialty: '心理治疗师',
                    hospital: '北京回龙观医院',
                    rating: 4.7,
                    reviews: 89,
                    distance: '5.2公里',
                    price: '¥200/次',
                    availability: '明天可约',
                    image: '👨‍⚕️',
                    address: '北京市昌平区回龙观镇',
                    phone: '010-82951336',
                    specialties: ['家庭治疗', '青少年心理', '创伤治疗'],
                    education: '首都医科大学硕士',
                    experience: '12年临床经验'
                }
            ];
        }

        // Load user data from localStorage
        function loadUserData() {
            const savedAppointments = localStorage.getItem('userAppointments');
            if (savedAppointments) {
                userAppointments = JSON.parse(savedAppointments);
            }
        }

        // Save user data to localStorage
        function saveUserData() {
            localStorage.setItem('userAppointments', JSON.stringify(userAppointments));
        }

        // Render all components
        function renderAllComponents() {
            renderCounselors();
            renderSupportGroups();
            renderResources();
            renderDoctors();
            renderAppointments();
        }

        // Render counselors
        function renderCounselors() {
            const container = document.getElementById('counselors-container');
            container.innerHTML = '';

            counselorsData.forEach(counselor => {
                const card = document.createElement('div');
                card.className = 'support-card rounded-2xl p-6';
                
                const statusClass = counselor.status === 'available' ? 'available-badge' : 
                                  counselor.status === 'busy' ? 'busy-badge' : 'offline-badge';
                const statusText = counselor.status === 'available' ? '在线可约' : 
                                 counselor.status === 'busy' ? '忙碌中' : '离线';

                card.innerHTML = `
                    <div class="text-center relative">
                        <div class="w-20 h-20 ${statusClass} rounded-full mx-auto mb-4 flex items-center justify-center">
                            <span class="text-white text-3xl">${counselor.image}</span>
                        </div>
                        <div class="absolute top-0 right-0">
                            <span class="px-2 py-1 bg-white text-xs rounded-full ${counselor.status === 'available' ? 'text-green-600' : counselor.status === 'busy' ? 'text-orange-600' : 'text-gray-600'}">${statusText}</span>
                        </div>
                        <h3 class="text-lg font-semibold text-gray-800 mb-1">${counselor.name}</h3>
                        <p class="text-sm text-gray-600 mb-2">${counselor.specialty}</p>
                        <p class="text-xs text-gray-500 mb-3">${counselor.experience}</p>
                        
                        <div class="flex items-center justify-center mb-3">
                            <div class="rating-stars text-sm mr-2">
                                ${'★'.repeat(Math.floor(counselor.rating))}${'☆'.repeat(5-Math.floor(counselor.rating))}
                            </div>
                            <span class="text-sm text-gray-600">${counselor.rating} (${counselor.reviews}条评价)</span>
                        </div>
                        
                        <div class="mb-4">
                            <p class="text-sm font-medium text-gray-800 mb-1">${counselor.price}</p>
                            <p class="text-xs text-gray-500 mb-2">下次可约: ${counselor.nextAvailable}</p>
                            <div class="flex flex-wrap justify-center gap-1">
                                ${counselor.languages.map(lang => `<span class="px-2 py-1 bg-blue-100 text-blue-800 text-xs rounded-full">${lang}</span>`).join('')}
                            </div>
                        </div>
                        
                        <button onclick="showCounselorDetails(${counselor.id})" class="w-full bg-blue-500 text-white py-2 px-4 rounded-lg hover:bg-blue-600 transition-colors mb-2">
                            查看详情
                        </button>
                        <button onclick="bookCounselor(${counselor.id})" class="w-full ${counselor.status === 'available' ? 'bg-green-500 hover:bg-green-600' : 'bg-gray-400 cursor-not-allowed'} text-white py-2 px-4 rounded-lg transition-colors" ${counselor.status !== 'available' ? 'disabled' : ''}>
                            ${counselor.status === 'available' ? '立即预约' : '暂不可约'}
                        </button>
                    </div>
                `;
                
                container.appendChild(card);
            });
        }

        // Render support groups
        function renderSupportGroups() {
            const container = document.getElementById('support-groups-container');
            container.innerHTML = '';

            supportGroupsData.forEach(group => {
                const card = document.createElement('div');
                card.className = 'support-card rounded-2xl p-6';
                
                card.innerHTML = `
                    <div class="flex items-start justify-between mb-4">
                        <div class="flex-1">
                            <h3 class="text-lg font-semibold text-gray-800 mb-2">${group.name}</h3>
                            <p class="text-sm text-gray-600 mb-3">${group.description}</p>
                        </div>
                        <span class="px-2 py-1 ${group.active ? 'bg-green-100 text-green-800' : 'bg-gray-100 text-gray-800'} text-xs rounded-full ml-2">
                            ${group.active ? '活跃中' : '休息中'}
                        </span>
                    </div>
                    
                    <div class="space-y-2 mb-4">
                        <div class="flex justify-between text-sm">
                            <span class="text-gray-600">成员数量:</span>
                            <span class="font-medium text-gray-800">${group.currentMembers}/${group.maxMembers}人</span>
                        </div>
                        <div class="flex justify-between text-sm">
                            <span class="text-gray-600">活动时间:</span>
                            <span class="font-medium text-gray-800">${group.meetingDay} ${group.nextMeeting}</span>
                        </div>
                        <div class="flex justify-between text-sm">
                            <span class="text-gray-600">活动形式:</span>
                            <span class="font-medium text-gray-800">${group.type}</span>
                        </div>
                        <div class="flex justify-between text-sm">
                            <span class="text-gray-600">时长:</span>
                            <span class="font-medium text-gray-800">${group.duration}</span>
                        </div>
                    </div>
                    
                    <div class="flex space-x-2">
                        <button onclick="showGroupDetails(${group.id})" class="flex-1 bg-blue-500 text-white py-2 px-4 rounded-lg hover:bg-blue-600 transition-colors">
                            查看详情
                        </button>
                        <button onclick="joinSupportGroup(${group.id})" class="flex-1 ${group.active ? 'bg-green-500 hover:bg-green-600' : 'bg-gray-400 cursor-not-allowed'} text-white py-2 px-4 rounded-lg transition-colors" ${!group.active ? 'disabled' : ''}>
                            ${group.active ? '加入小组' : '暂不可加入'}
                        </button>
                    </div>
                `;
                
                container.appendChild(card);
            });
        }

        // Render resources
        function renderResources(resources = null) {
            const container = document.getElementById('resource-results');
            const resourcesToShow = resources || resourcesData;
            container.innerHTML = '';

            if (resourcesToShow.length === 0) {
                container.innerHTML = `
                    <div class="text-center py-8">
                        <div class="text-gray-400 text-lg mb-2">未找到相关资源</div>
                        <p class="text-gray-500">请尝试其他搜索关键词或选择不同的分类</p>
                    </div>
                `;
                return;
            }

            resourcesToShow.forEach(resource => {
                const item = document.createElement('div');
                item.className = 'resource-item p-6 rounded-2xl';
                
                const typeColors = {
                    '文章': 'bg-blue-100 text-blue-800',
                    '音频': 'bg-green-100 text-green-800',
                    '视频': 'bg-red-100 text-red-800',
                    'PDF': 'bg-purple-100 text-purple-800'
                };

                item.innerHTML = `
                    <div class="flex items-start justify-between mb-4">
                        <div class="flex-1">
                            <div class="flex items-center mb-2">
                                <span class="px-2 py-1 ${typeColors[resource.type]} text-xs rounded-full mr-2">${resource.type}</span>
                                <span class="text-xs text-gray-500">${resource.duration}</span>
                                <span class="text-xs text-gray-500 ml-2">⭐ ${resource.rating}</span>
                            </div>
                            <h3 class="text-lg font-semibold text-gray-800 mb-2">${resource.title}</h3>
                            <p class="text-sm text-gray-600 mb-3">${resource.description}</p>
                            
                            <div class="flex flex-wrap gap-1 mb-3">
                                ${resource.tags.map(tag => `<span class="px-2 py-1 bg-gray-100 text-gray-700 text-xs rounded-full">${tag}</span>`).join('')}
                            </div>
                            
                            <div class="flex items-center justify-between text-xs text-gray-500">
                                <span>作者: ${resource.author}</span>
                                <span>发布日期: ${resource.date}</span>
                                <span>阅读: ${resource.readCount}次</span>
                            </div>
                        </div>
                        
                        <button onclick="accessResource(${resource.id})" class="ml-4 bg-blue-500 text-white px-4 py-2 rounded-lg hover:bg-blue-600 transition-colors">
                            查看详情
                        </button>
                    </div>
                `;
                
                container.appendChild(item);
            });
        }

        // Render doctors
        function renderDoctors(doctors = null) {
            const container = document.getElementById('doctor-results');
            const doctorsToShow = doctors || doctorsData;
            container.innerHTML = '';

            doctorsToShow.forEach(doctor => {
                const card = document.createElement('div');
                card.className = 'support-card rounded-2xl p-6';
                
                card.innerHTML = `
                    <div class="text-center">
                        <div class="w-16 h-16 bg-gradient-to-br from-orange-500 to-red-500 rounded-full mx-auto mb-4 flex items-center justify-center">
                            <span class="text-white text-2xl">${doctor.image}</span>
                        </div>
                        <h3 class="text-lg font-semibold text-gray-800 mb-1">${doctor.name}</h3>
                        <p class="text-sm text-gray-600 mb-2">${doctor.specialty}</p>
                        <p class="text-xs text-gray-500 mb-3">${doctor.hospital}</p>
                        
                        <div class="flex items-center justify-center mb-3">
                            <div class="rating-stars text-sm mr-2">
                                ${'★'.repeat(Math.floor(doctor.rating))}${'☆'.repeat(5-Math.floor(doctor.rating))}
                            </div>
                            <span class="text-sm text-gray-600">${doctor.rating} (${doctor.reviews}条评价)</span>
                        </div>
                        
                        <div class="space-y-2 text-sm mb-4">
                            <div class="flex justify-between">
                                <span class="text-gray-600">距离:</span>
                                <span class="font-medium text-gray-800">${doctor.distance}</span>
                            </div>
                            <div class="flex justify-between">
                                <span class="text-gray-600">费用:</span>
                                <span class="font-medium text-gray-800">${doctor.price}</span>
                            </div>
                            <div class="flex justify-between">
                                <span class="text-gray-600">可约时间:</span>
                                <span class="font-medium text-green-600">${doctor.availability}</span>
                            </div>
                        </div>
                        
                        <div class="flex space-x-2">
                            <button onclick="showDoctorDetails(${doctor.id})" class="flex-1 bg-blue-500 text-white py-2 px-4 rounded-lg hover:bg-blue-600 transition-colors">
                                查看详情
                            </button>
                            <button onclick="bookDoctor(${doctor.id})" class="flex-1 bg-orange-500 text-white py-2 px-4 rounded-lg hover:bg-orange-600 transition-colors">
                                预约咨询
                            </button>
                        </div>
                    </div>
                `;
                
                container.appendChild(card);
            });
        }

        // Render appointments
        function renderAppointments() {
            const container = document.getElementById('appointments-container');
            container.innerHTML = '';

            if (userAppointments.length === 0) {
                container.innerHTML = `
                    <div class="text-center py-8">
                        <div class="text-gray-400 text-lg mb-2">暂无预约</div>
                        <p class="text-gray-500">您还没有任何预约，快去预约咨询师或加入支持小组吧！</p>
                    </div>
                `;
                return;
            }

            userAppointments.forEach((appointment, index) => {
                const card = document.createElement('div');
                card.className = 'appointment-card rounded-2xl p-6 mb-4';
                
                const statusColor = appointment.status === 'confirmed' ? 'text-green-600 bg-green-100' :
                                  appointment.status === 'pending' ? 'text-yellow-600 bg-yellow-100' :
                                  'text-red-600 bg-red-100';

                card.innerHTML = `
                    <div class="flex items-start justify-between">
                        <div class="flex-1">
                            <div class="flex items-center mb-2">
                                <h3 class="text-lg font-semibold text-gray-800 mr-3">${appointment.title}</h3>
                                <span class="px-2 py-1 ${statusColor} text-xs rounded-full">
                                    ${appointment.status === 'confirmed' ? '已确认' : appointment.status === 'pending' ? '待确认' : '已取消'}
                                </span>
                            </div>
                            
                            <div class="grid grid-cols-1 md:grid-cols-3 gap-4 text-sm">
                                <div>
                                    <span class="text-gray-600">时间:</span>
                                    <span class="font-medium text-gray-800 ml-1">${appointment.datetime}</span>
                                </div>
                                <div>
                                    <span class="text-gray-600">类型:</span>
                                    <span class="font-medium text-gray-800 ml-1">${appointment.type}</span>
                                </div>
                                <div>
                                    <span class="text-gray-600">费用:</span>
                                    <span class="font-medium text-gray-800 ml-1">${appointment.price}</span>
                                </div>
                            </div>
                            
                            ${appointment.notes ? `
                                <div class="mt-3">
                                    <span class="text-gray-600 text-sm">备注:</span>
                                    <p class="text-sm text-gray-800 mt-1">${appointment.notes}</p>
                                </div>
                            ` : ''}
                        </div>
                        
                        <div class="flex space-x-2 ml-4">
                            ${appointment.status === 'confirmed' ? `
                                <button onclick="joinAppointment(${index})" class="bg-blue-500 text-white px-3 py-1 rounded text-sm hover:bg-blue-600 transition-colors">
                                    进入咨询
                                </button>
                            ` : ''}
                            <button onclick="cancelAppointment(${index})" class="bg-red-500 text-white px-3 py-1 rounded text-sm hover:bg-red-600 transition-colors">
                                取消预约
                            </button>
                        </div>
                    </div>
                `;
                
                container.appendChild(card);
            });
        }

        // Search functions
        function searchResources() {
            const searchTerm = document.getElementById('resource-search').value.toLowerCase();
            const category = document.getElementById('resource-category').value;
            
            let filteredResources = resourcesData;

            if (searchTerm) {
                filteredResources = filteredResources.filter(resource => 
                    resource.title.toLowerCase().includes(searchTerm) ||
                    resource.description.toLowerCase().includes(searchTerm) ||
                    resource.tags.some(tag => tag.toLowerCase().includes(searchTerm))
                );
            }

            if (category) {
                filteredResources = filteredResources.filter(resource => resource.category === category);
            }

            renderResources(filteredResources);
        }

        function searchDoctors() {
            const location = document.getElementById('location-search').value;
            const specialty = document.getElementById('doctor-specialty').value;
            
            let filteredDoctors = doctorsData;

            if (specialty) {
                filteredDoctors = filteredDoctors.filter(doctor => 
                    doctor.specialty.toLowerCase().includes(specialty.toLowerCase())
                );
            }

            renderDoctors(filteredDoctors);
        }

        // Detail modal functions
        function showCounselorDetails(counselorId) {
            const counselor = counselorsData.find(c => c.id === counselorId);
            if (!counselor) return;

            const modal = document.createElement('div');
            modal.className = 'fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4 modal';
            modal.innerHTML = `
                <div class="bg-white rounded-2xl p-8 max-w-2xl w-full max-h-90vh overflow-y-auto">
                    <div class="text-center mb-6">
                        <div class="w-24 h-24 bg-gradient-to-br from-blue-500 to-teal-500 rounded-full mx-auto mb-4 flex items-center justify-center">
                            <span class="text-white text-4xl">${counselor.image}</span>
                        </div>
                        <h2 class="text-2xl font-bold text-gray-800 mb-2">${counselor.name}</h2>
                        <p class="text-lg text-gray-600">${counselor.specialty}</p>
                    </div>
                    
                    <div class="space-y-6">
                        <div class="p-4 bg-blue-50 rounded-lg">
                            <h3 class="font-semibold text-blue-800 mb-2">专业背景</h3>
                            <p class="text-sm text-blue-700">${counselor.experience} · ${counselor.description}</p>
                        </div>
                        
                        <div class="p-4 bg-green-50 rounded-lg">
                            <h3 class="font-semibold text-green-800 mb-2">专业领域</h3>
                            <div class="flex flex-wrap gap-2">
                                ${counselor.specialties.map(specialty => `<span class="px-2 py-1 bg-green-100 text-green-800 text-xs rounded-full">${specialty}</span>`).join('')}
                            </div>
                        </div>
                        
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                            <div class="p-4 bg-gray-50 rounded-lg">
                                <h3 class="font-semibold text-gray-800 mb-2">服务信息</h3>
                                <div class="space-y-1 text-sm">
                                    <div><span class="text-gray-600">费用:</span> <span class="font-medium">${counselor.price}</span></div>
                                    <div><span class="text-gray-600">语言:</span> <span class="font-medium">${counselor.languages.join(', ')}</span></div>
                                    <div><span class="text-gray-600">可约时间:</span> <span class="font-medium text-green-600">${counselor.nextAvailable}</span></div>
                                </div>
                            </div>
                            
                            <div class="p-4 bg-gray-50 rounded-lg">
                                <h3 class="font-semibold text-gray-800 mb-2">评价信息</h3>
                                <div class="space-y-1 text-sm">
                                    <div class="flex items-center">
                                        <span class="rating-stars mr-1">★★★★★</span>
                                        <span class="font-medium">${counselor.rating}</span>
                                    </div>
                                    <div><span class="text-gray-600">${counselor.reviews}条评价</span></div>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="mt-8 flex space-x-3">
                        <button onclick="showBookingModal(${counselor.id})" class="flex-1 bg-green-500 text-white py-3 px-4 rounded-lg hover:bg-green-600 transition-colors">
                            立即预约
                        </button>
                        <button onclick="this.closest('.fixed').remove()" class="flex-1 bg-gray-200 text-gray-800 py-3 px-4 rounded-lg hover:bg-gray-300 transition-colors">
                            关闭
                        </button>
                    </div>
                </div>
            `;
            
            document.body.appendChild(modal);
        }

        function showGroupDetails(groupId) {
            const group = supportGroupsData.find(g => g.id === groupId);
            if (!group) return;

            const modal = document.createElement('div');
            modal.className = 'fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4 modal';
            modal.innerHTML = `
                <div class="bg-white rounded-2xl p-8 max-w-2xl w-full max-h-90vh overflow-y-auto">
                    <div class="text-center mb-6">
                        <h2 class="text-2xl font-bold text-gray-800 mb-2">${group.name}</h2>
                        <p class="text-lg text-gray-600">${group.description}</p>
                    </div>
                    
                    <div class="space-y-6">
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                            <div class="p-4 bg-blue-50 rounded-lg">
                                <h3 class="font-semibold text-blue-800 mb-2">活动信息</h3>
                                <div class="space-y-1 text-sm">
                                    <div><span class="text-blue-600">活动时间:</span> <span class="font-medium">${group.meetingDay} ${group.nextMeeting}</span></div>
                                    <div><span class="text-blue-600">活动形式:</span> <span class="font-medium">${group.type}</span></div>
                                    <div><span class="text-blue-600">活动时长:</span> <span class="font-medium">${group.duration}</span></div>
                                    <div><span class="text-blue-600">主持人:</span> <span class="font-medium">${group.facilitator}</span></div>
                                </div>
                            </div>
                            
                            <div class="p-4 bg-green-50 rounded-lg">
                                <h3 class="font-semibold text-green-800 mb-2">成员信息</h3>
                                <div class="space-y-1 text-sm">
                                    <div><span class="text-green-600">总成员:</span> <span class="font-medium">${group.members}人</span></div>
                                    <div><span class="text-green-600">当前成员:</span> <span class="font-medium">${group.currentMembers}人</span></div>
                                    <div><span class="text-green-600">剩余名额:</span> <span class="font-medium">${group.maxMembers - group.currentMembers}人</span></div>
                                    <div><span class="text-green-600">小组状态:</span> <span class="font-medium ${group.active ? 'text-green-600' : 'text-gray-600'}">${group.active ? '活跃中' : '休息中'}</span></div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="p-4 bg-purple-50 rounded-lg">
                            <h3 class="font-semibold text-purple-800 mb-2">小组规则</h3>
                            <ul class="text-sm text-purple-700 space-y-1">
                                <li>• 尊重每位成员的隐私和分享</li>
                                <li>• 按时参加活动，如有特殊情况请提前告知</li>
                                <li>• 保持开放和包容的态度</li>
                                <li>• 不在小组外讨论成员的分享内容</li>
                                <li>• 积极参与讨论和互动练习</li>
                            </ul>
                        </div>
                    </div>
                    
                    <div class="mt-8 flex space-x-3">
                        <button onclick="joinSupportGroup(${group.id})" class="flex-1 ${group.active && group.currentMembers < group.maxMembers ? 'bg-green-500 hover:bg-green-600' : 'bg-gray-400 cursor-not-allowed'} text-white py-3 px-4 rounded-lg transition-colors" ${!group.active || group.currentMembers >= group.maxMembers ? 'disabled' : ''}>
                            ${group.active && group.currentMembers < group.maxMembers ? '加入小组' : '名额已满'}
                        </button>
                        <button onclick="this.closest('.fixed').remove()" class="flex-1 bg-gray-200 text-gray-800 py-3 px-4 rounded-lg hover:bg-gray-300 transition-colors">
                            关闭
                        </button>
                    </div>
                </div>
            `;
            
            document.body.appendChild(modal);
        }

        function showDoctorDetails(doctorId) {
            const doctor = doctorsData.find(d => d.id === doctorId);
            if (!doctor) return;

            const modal = document.createElement('div');
            modal.className = 'fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4 modal';
            modal.innerHTML = `
                <div class="bg-white rounded-2xl p-8 max-w-2xl w-full max-h-90vh overflow-y-auto">
                    <div class="text-center mb-6">
                        <div class="w-24 h-24 bg-gradient-to-br from-orange-500 to-red-500 rounded-full mx-auto mb-4 flex items-center justify-center">
                            <span class="text-white text-4xl">${doctor.image}</span>
                        </div>
                        <h2 class="text-2xl font-bold text-gray-800 mb-2">${doctor.name}</h2>
                        <p class="text-lg text-gray-600">${doctor.specialty}</p>
                        <p class="text-sm text-gray-500">${doctor.hospital}</p>
                    </div>
                    
                    <div class="space-y-6">
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                            <div class="p-4 bg-blue-50 rounded-lg">
                                <h3 class="font-semibold text-blue-800 mb-2">基本信息</h3>
                                <div class="space-y-1 text-sm">
                                    <div><span class="text-blue-600">学历:</span> <span class="font-medium">${doctor.education}</span></div>
                                    <div><span class="text-blue-600">经验:</span> <span class="font-medium">${doctor.experience}</span></div>
                                    <div><span class="text-blue-600">距离:</span> <span class="font-medium">${doctor.distance}</span></div>
                                    <div><span class="text-blue-600">费用:</span> <span class="font-medium">${doctor.price}</span></div>
                                </div>
                            </div>
                            
                            <div class="p-4 bg-green-50 rounded-lg">
                                <h3 class="font-semibold text-green-800 mb-2">联系信息</h3>
                                <div class="space-y-1 text-sm">
                                    <div><span class="text-green-600">地址:</span> <span class="font-medium">${doctor.address}</span></div>
                                    <div><span class="text-green-600">电话:</span> <span class="font-medium">${doctor.phone}</span></div>
                                    <div><span class="text-green-600">可约时间:</span> <span class="font-medium text-green-600">${doctor.availability}</span></div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="p-4 bg-purple-50 rounded-lg">
                            <h3 class="font-semibold text-purple-800 mb-2">专业领域</h3>
                            <div class="flex flex-wrap gap-2">
                                ${doctor.specialties.map(specialty => `<span class="px-2 py-1 bg-purple-100 text-purple-800 text-xs rounded-full">${specialty}</span>`).join('')}
                            </div>
                        </div>
                        
                        <div class="p-4 bg-gray-50 rounded-lg">
                            <h3 class="font-semibold text-gray-800 mb-2">患者评价</h3>
                            <div class="space-y-2">
                                <div class="flex items-center">
                                    <div class="rating-stars mr-2">★★★★★</div>
                                    <span class="font-medium">${doctor.rating}</span>
                                    <span class="text-gray-600 ml-2">(${doctor.reviews}条评价)</span>
                                </div>
                                <div class="text-sm text-gray-600">
                                    <p>"医生非常专业，态度也很好，治疗效果明显。"</p>
                                    <p>"耐心细致，能够很好地理解患者的需求。"</p>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="mt-8 flex space-x-3">
                        <button onclick="showBookingModal(null, ${doctor.id})" class="flex-1 bg-orange-500 text-white py-3 px-4 rounded-lg hover:bg-orange-600 transition-colors">
                            立即预约
                        </button>
                        <button onclick="this.closest('.fixed').remove()" class="flex-1 bg-gray-200 text-gray-800 py-3 px-4 rounded-lg hover:bg-gray-300 transition-colors">
                            关闭
                        </button>
                    </div>
                </div>
            `;
            
            document.body.appendChild(modal);
        }

        // Booking modal
        function showBookingModal(counselorId = null, doctorId = null) {
            const professional = counselorId ? 
                counselorsData.find(c => c.id === counselorId) : 
                doctorsData.find(d => d.id === doctorId);
            
            if (!professional) return;

            const type = counselorId ? '咨询' : '医疗';
            const timeSlots = [
                '09:00-10:00', '10:00-11:00', '11:00-12:00',
                '14:00-15:00', '15:00-16:00', '16:00-17:00'
            ];

            const modal = document.createElement('div');
            modal.className = 'fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4 modal';
            modal.innerHTML = `
                <div class="bg-white rounded-2xl p-8 max-w-md w-full">
                    <div class="text-center mb-6">
                        <h2 class="text-xl font-bold text-gray-800 mb-2">预约${type}</h2>
                        <p class="text-gray-600">${professional.name} · ${professional.price}</p>
                    </div>
                    
                    <div class="space-y-4">
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">选择日期</label>
                            <input type="date" id="appointment-date" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" min="${new Date().toISOString().split('T')[0]}">
                        </div>
                        
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">选择时间</label>
                            <div class="grid grid-cols-2 gap-2" id="time-slots">
                                ${timeSlots.map(slot => `
                                    <button onclick="selectTimeSlot(this, '${slot}')" class="appointment-slot p-2 border border-gray-300 rounded text-sm hover:bg-blue-50 transition-colors">
                                        ${slot}
                                    </button>
                                `).join('')}
                            </div>
                        </div>
                        
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">备注 (可选)</label>
                            <textarea id="appointment-notes" rows="3" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="请描述您的主要问题或需求..."></textarea>
                        </div>
                    </div>
                    
                    <div class="mt-8 flex space-x-3">
                        <button onclick="confirmBooking(${counselorId}, ${doctorId})" class="flex-1 bg-green-500 text-white py-2 px-4 rounded-lg hover:bg-green-600 transition-colors">
                            确认预约
                        </button>
                        <button onclick="this.closest('.fixed').remove()" class="flex-1 bg-gray-200 text-gray-800 py-2 px-4 rounded-lg hover:bg-gray-300 transition-colors">
                            取消
                        </button>
                    </div>
                </div>
            `;
            
            document.body.appendChild(modal);
        }

        function selectTimeSlot(element, time) {
            // Remove selected class from all slots
            document.querySelectorAll('.appointment-slot').forEach(slot => {
                slot.classList.remove('selected');
            });
            
            // Add selected class to clicked slot
            element.classList.add('selected');
            
            // Store selected time
            window.selectedTimeSlot = time;
        }

        function confirmBooking(counselorId, doctorId) {
            const date = document.getElementById('appointment-date').value;
            const notes = document.getElementById('appointment-notes').value;
            const time = window.selectedTimeSlot;

            if (!date || !time) {
                showNotification('预约失败', '请选择预约日期和时间', 'error');
                return;
            }

            const professional = counselorId ? 
                counselorsData.find(c => c.id === counselorId) : 
                doctorsData.find(d => d.id === doctorId);

            const appointment = {
                id: Date.now(),
                title: `${professional.name} · ${professional.specialty}`,
                datetime: `${date} ${time}`,
                type: counselorId ? '在线咨询' : '医疗咨询',
                price: professional.price,
                status: 'pending',
                notes: notes,
                professionalId: professional.id,
                professionalName: professional.name
            };

            userAppointments.push(appointment);
            saveUserData();
            renderAppointments();

            document.querySelector('.fixed').remove();
            showNotification('预约成功', `您已成功预约${professional.name}，请等待确认`, 'success');
        }

        // Action functions
        function bookCounselor(counselorId) {
            const counselor = counselorsData.find(c => c.id === counselorId);
            if (counselor && counselor.status === 'available') {
                showBookingModal(counselorId, null);
            } else {
                showNotification('预约失败', '该咨询师当前不可预约', 'error');
            }
        }

        function joinSupportGroup(groupId) {
            const group = supportGroupsData.find(g => g.id === groupId);
            if (group && group.active && group.currentMembers < group.maxMembers) {
                const appointment = {
                    id: Date.now(),
                    title: `支持小组: ${group.name}`,
                    datetime: `${group.nextMeeting}`,
                    type: '支持小组',
                    price: '免费',
                    status: 'confirmed',
                    notes: `加入${group.name}，主持人：${group.facilitator}`,
                    groupId: group.id,
                    groupName: group.name
                };

                userAppointments.push(appointment);
                group.currentMembers++;
                saveUserData();
                renderSupportGroups();
                renderAppointments();
                showNotification('加入成功', `您已成功加入${group.name}！`, 'success');
            } else {
                showNotification('加入失败', '该小组当前不可加入或名额已满', 'error');
            }
        }

        function accessResource(resourceId) {
            const resource = resourcesData.find(r => r.id === resourceId);
            if (resource) {
                showResourceModal(resource);
            }
        }

        function showResourceModal(resource) {
            const modal = document.createElement('div');
            modal.className = 'fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4 modal';
            modal.innerHTML = `
                <div class="bg-white rounded-2xl p-8 max-w-4xl w-full max-h-90vh overflow-y-auto">
                    <div class="flex items-start justify-between mb-6">
                        <div class="flex-1">
                            <h2 class="text-2xl font-bold text-gray-800 mb-2">${resource.title}</h2>
                            <div class="flex items-center space-x-4 text-sm text-gray-600">
                                <span>作者: ${resource.author}</span>
                                <span>发布日期: ${resource.date}</span>
                                <span>类型: ${resource.type}</span>
                                <span>⭐ ${resource.rating}</span>
                            </div>
                        </div>
                        <button onclick="this.closest('.fixed').remove()" class="text-gray-400 hover:text-gray-600">
                            <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
                            </svg>
                        </button>
                    </div>
                    
                    <div class="prose max-w-none">
                        <div class="p-4 bg-blue-50 rounded-lg mb-6">
                            <p class="text-blue-800">${resource.description}</p>
                        </div>
                        
                        <div class="p-4 bg-gray-50 rounded-lg">
                            <h3 class="font-semibold text-gray-800 mb-3">内容预览</h3>
                            <p class="text-gray-700">${resource.content}</p>
                        </div>
                        
                        <div class="mt-6 p-4 bg-green-50 rounded-lg">
                            <h3 class="font-semibold text-green-800 mb-2">标签</h3>
                            <div class="flex flex-wrap gap-2">
                                ${resource.tags.map(tag => `<span class="px-3 py-1 bg-green-100 text-green-800 text-sm rounded-full">${tag}</span>`).join('')}
                            </div>
                        </div>
                    </div>
                    
                    <div class="mt-8 flex space-x-3">
                        <button onclick="showNotification('资源访问', '正在打开完整版本...', 'info')" class="flex-1 bg-blue-500 text-white py-3 px-4 rounded-lg hover:bg-blue-600 transition-colors">
                            查看完整内容
                        </button>
                        <button onclick="this.closest('.fixed').remove()" class="flex-1 bg-gray-200 text-gray-800 py-3 px-4 rounded-lg hover:bg-gray-300 transition-colors">
                            关闭
                        </button>
                    </div>
                </div>
            `;
            
            document.body.appendChild(modal);
        }

        function bookDoctor(doctorId) {
            showBookingModal(null, doctorId);
        }

        function joinAppointment(index) {
            const appointment = userAppointments[index];
            showNotification('进入咨询', `正在为您连接${appointment.professionalName || appointment.groupName}...`, 'info');
        }

        function cancelAppointment(index) {
            const appointment = userAppointments[index];
            
            const modal = document.createElement('div');
            modal.className = 'fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4 modal';
            modal.innerHTML = `
                <div class="bg-white rounded-2xl p-8 max-w-md w-full text-center">
                    <div class="w-16 h-16 bg-red-100 rounded-full mx-auto mb-4 flex items-center justify-center">
                        <svg class="w-8 h-8 text-red-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L3.732 16.5c-.77.833.192 2.5 1.732 2.5z"></path>
                        </svg>
                    </div>
                    <h3 class="text-xl font-bold text-gray-800 mb-4">确认取消预约</h3>
                    <p class="text-gray-600 mb-6">您确定要取消预约 "${appointment.title}" 吗？此操作不可撤销。</p>
                    <div class="flex space-x-3">
                        <button onclick="this.closest('.fixed').remove()" class="flex-1 bg-gray-200 text-gray-800 py-2 px-4 rounded-lg hover:bg-gray-300 transition-colors">
                            返回
                        </button>
                        <button onclick="confirmCancelAppointment(${index})" class="flex-1 bg-red-500 text-white py-2 px-4 rounded-lg hover:bg-red-600 transition-colors">
                            确认取消
                        </button>
                    </div>
                </div>
            `;
            
            document.body.appendChild(modal);
        }

        function confirmCancelAppointment(index) {
            userAppointments.splice(index, 1);
            saveUserData();
            renderAppointments();
            document.querySelector('.fixed').remove();
            showNotification('取消成功', '预约已成功取消', 'success');
        }

        // Utility functions
        function showAllCounselors() {
            showNotification('查看咨询师', '正在加载更多咨询师信息...', 'info');
        }

        function createSupportGroup() {
            showNotification('创建小组', '小组创建功能即将上线！', 'info');
        }

        function showNotification(title, message, type) {
            const notification = document.createElement('div');
            const bgColor = type === 'success' ? 'bg-green-50 border-green-400' : 
                           type === 'error' ? 'bg-red-50 border-red-400' : 'bg-blue-50 border-blue-400';
            const textColor = type === 'success' ? 'text-green-800' : 
                             type === 'error' ? 'text-red-800' : 'text-blue-800';
            
            notification.className = `fixed top-4 right-4 ${bgColor} border-l-4 p-4 rounded-lg shadow-lg z-50`;
            notification.innerHTML = `
                <div class="flex">
                    <div class="ml-3">
                        <p class="text-sm font-medium ${textColor}">${title}</p>
                        <p class="text-sm ${textColor.replace('800', '700')}">${message}</p>
                    </div>
                </div>
            `;
            
            document.body.appendChild(notification);
            
            setTimeout(() => {
                if (notification.parentNode) {
                    notification.remove();
                }
            }, 3000);
        }
    </script>
</body>
</html>